using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;

#if UNITY_EDITOR
using UnityEditor;
#endif
public class SFrameworkGate : MonoBehaviour
{
    public static string rootPath => Application.dataPath + "/only-sframework/";
    public static string appDefinePath => "Assets/only-sframework/Data/Database/";

    public static bool InEditor
    {
        get
        {
#if DEBUG && UNITY_EDITOR
            return true;
#endif
            return false;
        }
    }
    public static bool IsPlaying => Application.isPlaying;

    public static SFrameworkGate instance;
#if DEBUG && UNITY_EDITOR
    [InitializeOnLoadMethod]
#else
    [RuntimeInitializeOnLoadMethod]
#endif
    public static void BootGate()
    {
        var gateGo = "SFrameworkGate".GlobalUniqueGameObject();
        var gate = gateGo.UniqueComponent<SFrameworkGate>();
        instance = gate;

        initSequence.Clear();

        initSequence[0] = () =>
        {
            var Observer = gateGo.UniqueComponent<ObserverSystem>();
            Observer.InitObserverSystem();
        };

        initSequence[1] = () =>
        {
            var lifeSystem = gateGo.UniqueComponent<VLifeSystem>();
            lifeSystem.Init();
        };

        initSequence[2] = () =>
        {
            var llmGate = gateGo.UniqueComponent<VLLMGate>();
            llmGate.Init();
        };

        initSequence[3] = () =>
        {
            var PWareHouse = gateGo.UniqueComponent<PWarehouse>();
            PWareHouse.InitWarehouse();
        };

        initSequence[4] = () =>
        {
            VAnimationDefine.LoadAssets();
        };

        //升序调用一遍完成初始化 , 可以考虑用特性标注
        initSequence
        .OrderBy(pair => pair.Key)
        .ToList()
        .ForEach(x => x.Value?.Invoke());
        Debug.Log("SGate Init");
    }

    public static Dictionary<int, Action> initSequence = new();

}
